package ui.activity.home.presenter;


import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import Bean.MPOSBean;
import base.BaseBiz;
import coom.Constants;
import ui.activity.home.biz.PickMachineBiz;
import ui.activity.home.contract.PickMachineContract;

/**
 * Created by chenjian on 19/2/26
 */

public class PickMachinePresenter implements PickMachineContract.Presenter {

    PickMachineContract.View view;
    PickMachineBiz pickMachineBiz;
    List<MPOSBean.ChildrenBean> list = new ArrayList<>();


    @Inject
    public PickMachinePresenter(PickMachineContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        pickMachineBiz = (PickMachineBiz) biz;
    }


    @Override
    public void getPosList(boolean isRefresh, String type) {
        if (isRefresh) {
            list.clear();
        }
        view.loading(true);
        String url = Constants.modelListUrl + type;
        pickMachineBiz.getPosModelList(url, new BaseBiz.Callback<MPOSBean>() {
            @Override
            public void onSuccess(MPOSBean info) {
                list.addAll(info.getChildren());
                view.upDateUI(list);
                view.hasLoadMore(false);
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
                view.loading(false);
            }

            @Override
            public void onFailure(MPOSBean info) {
                view.loading(false);
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
            }
        });

    }

}
